package cn.wolfcode.postbar.redis.util;

import cn.wolfcode.postbar.util.Consts;
import lombok.Getter;
/**
 * Created by chenzhaoguang on 2021/1/12.
 * redis的key的管理类
 * 约定: 一个redis key 映射一个枚举实例
 */
@Getter
public enum RedisKeys {

    // 登陆的token实例
    USER_LOGIN_TOKEN("user_login_token", Consts.USER_INFO_TOKEN_VAI_TIME*60L);

    private String prefix; //key的前缀
    private Long time;   //key的有效时间,单位s

    //有参构造器
    private RedisKeys(String prefix,Long time){
        this.prefix = prefix;
        this.time = time;
    }

    //拼接出完整redis的key
    public String join(String... values){
        // 单个
       // return this.prefix + ":" + value;
        //多个
        StringBuilder builder = new StringBuilder(80);
        builder.append(this.prefix);
        for (String value : values) {
            builder.append(":").append(value);
        }
        return builder.toString();
    }
}
